<template>
    <div>
        <div class="outmain ba_f formwidth">
            <div class="shuju_title mar_b20">
                <div class="shuju_title_text">
                    <span>美团设置</span>
                </div>
            </div>
            <div class="ba_f8 pad_20">
                <div class="lh25 msgtext fon_12">
                    温馨提示：目前仅支持一键获取商户的美团外卖订单，进行统一管理；<br>
                    1、需要先申请美团商家开放平台开发者账号，申请地址；<a href="https://developer.meituan.com/ka" target="_blank" class="color_9">https://developer.meituan.com/ka</a>；<br>
                    2、管理中心-创建应用-企业应用-企业应用-勾选全部应用权限-其他内容按实际填写，保存即可；<br>
                    3、需要商户已签约美团外卖平台。
                </div>
            </div>
            <el-tabs v-model="activeName" @tab-click="handleClick">
                <el-tab-pane label="美团开放平台" name="1">
                    <el-form ref="form" :model="form" label-width="180px" class="mar_t20">
                        <el-form-item label="开关">
                            <el-radio-group v-model="form.open">
                                <el-radio label="1">开启</el-radio>
                                <el-radio label="2">关闭</el-radio>
                            </el-radio-group>
                        </el-form-item>
                        <el-form-item label="AppID" prop="appId" :required="true" v-show="form.open=='1'">
                            <el-input v-model="form.appId" placeholder="请输入美团开放平台开发者AppID"></el-input>
                            <div class="yb_margin lh16">请输入美团开放平台开发者AppID</div>
                        </el-form-item>
                        <el-form-item label="AppSecret"  :required="true" v-show="form.open=='1'">
                            <el-input v-model="form.appSecret" placeholder="请输入团开放平台开发者AppSecret"></el-input>
                            <div class="yb_margin lh16">请输入团开放平台开发者AppSecret</div>
                        </el-form-item>
                    </el-form>
                </el-tab-pane>
            </el-tabs>
        </div>
        <div class="mar_t20 ba_f pad_20 t_c">
            <el-button type="primary" @click="onSubmit">保存</el-button>
        </div>
    </div>
</template>
<script>
    import {getConfig, postConfig} from "@/api/setup";

    export default {
        created() {
            this.init();
        },
        data() {
            return {
                activeName: '1',
                form: {
                    appId: '',
                    appSecret: '',
                    open: '2',
                },
            }
        },
        methods: {
            async init() {
                this.bus.$emit('loading', true);
                this.formData()
            },
            async handleClick() {
                this.formData()
            },
            async formData() {
                const {data} = await getConfig({ident: 'meituanSet'});
                this.form2 = this.form
                this.form = Object.assign(this.form2, data);
                this.bus.$emit('loading', false)
            },
            async onSubmit() {
                this.$refs["form"].validate(async (valid) => {
                    if (valid) {
                        this.form.ident = 'meituanSet'
                        this.form.identName = '美团设置'
                        const {msg} = await postConfig(this.form);
                        this.$baseMessage(msg, "success");
                        this.init();
                    } else {
                        return false;
                    }
                });
            },
        }
    }
</script>
